﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FDEE.Model
{
    /// <summary>
    /// 钢筋混凝土预制板
    /// </summary>
    public class RCPlate : PlateBase
    {
        public RCPlate(string typeName, string pierNumber, int width, eSubType type, bool hasHole)
            : base(typeName, pierNumber, width, type, hasHole)
        {
            if (width < 850 || width > 1800)
            {
                throw new Exception("宽度超过设计范围");
            }
        }

        public override void SetRebarList()
        {
            int NumN2;
            if (HasHole)
            {
                double w = (Width - 240 - 30 - 30) * 0.5;
                NumN2 = ((int)(w / 150) + 1) * 2;
            }
            else
            {
                double w = (Width - 30 - 30);
                NumN2 = ((int)(w / 150) + 1);
            }
            RebarList.Add(new MARebarRecord(2, 0, "", eDB.DB12, Length - 60, NumN2, eShapeType.MA));

            int NumP;
            if (Width <= 1050)
            {
                NumP = 3;
            }
            else if (Width <= 1425)
            {
                NumP = 4;
            }
            else
            {
                NumP = 5;
            }

            int NumN3 = 0;
            switch (pType)
            {
                //1.2
                case eSubType.A:
                    RebarList.Add(new M2ABCDRebarRecord(1, 0, "", eDB.DB16,100, 480, Width, 480, 11, eShapeType.M2ABCD));
                    NumN3 = 4;
                    break;
                 //0.7
                case eSubType.B:
                    RebarList.Add(new M2ABCDRebarRecord(1, 0, "", eDB.DB16,100, 480, Width, 480, 7, eShapeType.M2ABCD));
                    NumN3 = 2;
                    break;
                //0.5
                case eSubType.C:
                    RebarList.Add(new M2ABCDRebarRecord(1, 0, "", eDB.DB16,100, 480, Width, 480, 5, eShapeType.M2ABCD));
                    NumN3 = 2;
                    break;
                default:
                    break;
            }
            int A = 40;
            int lx = 268;
            double B = (Width - 300) / (NumP - 1) - 150;
            int LenN3 = (int)Math.Round(A + lx * NumP + B * (NumP - 1) + A, 0, MidpointRounding.AwayFromZero);

            string FormulaN3 = string.Format("L=2A+{0:F0}Lx+{1:F0}B", NumP, NumP - 1);
            RebarList.Add(new MWaveRebarRecord(3, 0, "", eDB.DB10, A, lx, (int)Math.Round(B, 0, MidpointRounding.AwayFromZero),
                LenN3, NumN3, FormulaN3, eShapeType.MWAVE));
            RebarList.Sort();
        }
    }
}
